<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 24/01/2019
 * Time: 14:30
 */

namespace App\Modules\UCenter;


use App\Modules\AdapterApi;
use App\Services\User\UserIndex;

class BaseUcenter extends AdapterApi
{
    /**
     * 检测用户是否登录成功，
     * 如果登录成功，
     * 则返回用户信息，
     * 否则提示用户登录。
     * @param $token
     * @return array
     */
    protected function isLogin()
    {
        $token = ($this->postData)['token'];
        $info = $tokenContent = UserIndex::Token()->hGetAll($token);
        if (!isset($info['res']['id'])) {
            return auto_failure(null, '请登录');
        }else{

            foreach ($info['res'] as $k => &$v) {
                if (in_array($k, ['fund_etc', 'county_text', 'city_text', 'province_text', 'other_info', 'enterprise_info']))
                    $v = json_decode($v, true);
            }
            return $info;
        }
    }
}
